package ${controllerPackageName};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zksz.common.base.BaseController;
import com.zksz.common.enums.ResultEnum;
import com.zksz.common.util.PageUtil;
import com.zksz.common.util.ResultUtil;
import com.zksz.common.vo.PageVo;
import com.zksz.common.vo.Result;
import ${entityPackageName}.${className?cap_first};
import ${servicePackageName}.${className?cap_first}Service;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @description   ${description}
* @author        ${author}
* @date          ${createTime}
* @version       ${version}
**/
@Slf4j
@Transactional
@RequestMapping("/${className}")
@RestController
@Api(value = "${description}", tags = {"${description}接口"})
public class ${className?cap_first}Controller  extends BaseController{

    @Autowired
    private ${className?cap_first}Service service;

    @ApiOperation(value = "查询带分页列表", notes = "查询带分页列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page_number", value = "第几页", dataType = "String", required = false, paramType = "query"),
        @ApiImplicitParam(name = "page_size", value = "每页数量", dataType = "String", required = false, paramType = "query"),
        @ApiImplicitParam(name = "sort_field", value = "排序字段", dataType = "String", required = false, paramType = "query"),
        @ApiImplicitParam(name = "order_type", value = "排序方式asc/desc", dataType = "String", required = false, paramType = "query")
    })
    @ApiOperationSupport(ignoreParameters = {
        <#list columnMap?keys as column>"${columnMap["${column}"][0]}"<#if columnMap?size!=(column_index+1)>, </#if></#list>
    })
    @GetMapping("/findPage")
    public Result<IPage<${className?cap_first}>> findPage(@ModelAttribute PageVo pageVo,@ModelAttribute ${className?cap_first} ${className}) {
        IPage<${className?cap_first}> page = service.findPage(PageUtil.initMpPage(pageVo),${className});
        return new ResultUtil<IPage<${className?cap_first}>>().setData(page);
    }

    @ApiOperation(value = "查询不带分页列表", notes = "查询不带分页列表")
    @ApiOperationSupport(ignoreParameters = {
        <#list columnMap?keys as column>"${columnMap["${column}"][0]}"<#if columnMap?size!=(column_index+1)>, </#if></#list>
    })
    @GetMapping("/findList")
    public Result<List<${className?cap_first}>> findList(@ModelAttribute ${className?cap_first} ${className}) {
        List<${className?cap_first}> list = service.findList(${className});
        return new ResultUtil<List<${className?cap_first}>>().setData(list);
    }

    @ApiOperation(value = "通过ID查询", notes = "通过ID查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID", dataType = "String", required = true, paramType = "query")
    })
    @GetMapping("/findById")
    public Result<${className?cap_first}> findById(String id) {
        ${className?cap_first} ${className} = service.findById(id);
        return new ResultUtil<${className?cap_first}>().setData(${className});
    }

    @ApiOperation(value = "添加", notes = "添加")
    @ApiOperationSupport(ignoreParameters = {
        "id", "created_by", "created_time", "updated_by", "updated_time", "is_delete"
    })
    @PostMapping("/save")
    public Result save(@RequestBody ${className?cap_first} ${className}) {
        boolean boo = service.add(${className});
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnum.FAIL.getReasonPhraseCN());
        }
    }

    @ApiOperation(value = "修改", notes = "修改")
    @ApiOperationSupport(ignoreParameters = {
        "created_by", "created_time", "updated_by", "updated_time", "is_delete"
    })
    @PostMapping("/update")
    public Result update(@RequestBody ${className?cap_first} ${className}) {
        boolean boo = service.update(${className});
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnum.FAIL.getReasonPhraseCN());
        }
    }

    @ApiOperation(value = "删除", notes = "删除【逻辑删除】")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        boolean boo = service.delete(id);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnum.FAIL.getReasonPhraseCN());
        }
    }

}
